package vsa.migrations.junit.launcher;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import vsa.migrations.junit.JunitMigrationApplication;

/**
 * Class starts a junit migration from commandline
 * @author oleym
 *
 */
public class JunitMigrationCliLauncher {


	/**
	 * main-method
	 * @param args  arguments
	 * @throws IOException exception
	 */
	public static void main(String[] args) throws Exception {

		if (args.length < 1) {

			System.out.println ("Usage: ");
			System.out.println ("Step to the project, you want to migrate, then call:");
			System.out.println ("");
			System.out.println ("");
			System.out.println ("vsa.migrations.junit TESTSRCPATH [-debug] [-revert]");
			System.out.println ("");
			System.out.println ("");
			System.out.println ("  TESTSRCPATH: sourcepath to migrate (e.g test/src)");
			System.out.println ("  [-debug]   : Logging in debug mode"); 
			System.out.println ("  [-revert]  : Only revert without migrating");

			return;
		}
        File testsrc = new File (args [0]);
        boolean onlyRevert = false;
        
        
        for (String next: args) {
        	if (next.equals("-debug")) {
        		System.out.println ("set logging to debug");
        		
        		Logger logger = Logger.getLogger(""); 
        		logger.setLevel(Level.FINER);
        		logger.getHandlers() [0].setLevel(Level.FINER);
        	}
        	
        	if (next.equals("-revert")) {
        		onlyRevert = true;
        	}
        }
        
        
		Logger logger = Logger.getLogger(JunitMigrationApplication.class.getName());
		
		logger.info("Sourcepath    : " + testsrc.getAbsolutePath());
		logger.info("Only revert   : " + onlyRevert);
		
		logger.info("Loglevel info");
		logger.fine("Loglevel fine");
		logger.finer("Loglevel finer");
		logger.finest("Loglevel finest");

        JunitMigrationApplication app = new JunitMigrationApplication();
        app.revertPath(testsrc);
        
        if (! onlyRevert)
           app.migratePath(testsrc);
	}

	
}
